<?php

class Files extends Controller {
	
	function Files()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$this->load->helper('form');
		$this->load->helper('directory');

		$data['title'] = "GCMS >> Files";
		$data['heading'] = "Files";
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
		$this->_login_check($data, 'file_view');

	}

	function upload()
	{	
		$this->load->helper('form');
		$this->load->helper('directory');

		$data['title'] = "GCMS >> Files >> Upload";
		$data['heading'] = "Files >> Upload";
		$data['style'] = base_url().'system/application/views/content.css';
		
		$data['header'] = $this->load->view('header', $data, true);
		$data['footer'] = $this->load->view('footer', $data, true);
		$data['dir'] = $this->uri->segment(3);
		$this->_login_check($data, 'file_upload');
	}
	

	
	function upload1()
	{	
		//upload config options
		$config['upload_path'] = './'.$_POST['dir'].'/';
		$config['allowed_types'] = 'gif|jpg|png|doc|pdf|ppt|xls|txt|pub|psd';
		$config['overwrite'] = true;
		$this->load->library('upload', $config);
	
		if($this->upload->do_upload()){
			redirect('/files', 'refresh');
		} else {
			echo 'Error: File failed to upload:<br />'.$this->upload->display_errors();
		}
	}
	
	function _login_check($data, $dest)
	{
		$this->load->library('session');
		$this->load->library('validation');
		$logged_in = $this->session->userdata('logged_in');
		if(!$logged_in){
			$this->load->view('login', $data);
		} else {
			$this->load->view($dest, $data);
		}
	}
	
}
?>